package com.huobao.yunying.activitys_hehuoren;

import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public abstract class Act_TabBase extends HuobaoBaseActivity implements OnCheckedChangeListener {

	private RadioGroup radioGroup;
	private RadioButton rb_shouye, rb_fenlei, rb_jhc, rb_wode;
	/**
	 * 左上
	 */
	private TextView tv_1_title, tv_1;
	/**
	 * 右上
	 */
	private TextView tv_2_title, tv_2;
	/**
	 * 左下
	 */
	private TextView tv_3_title, tv_3;
	/**
	 * 右下
	 */
	private TextView tv_4_title, tv_4, tv_4_content;

	@Override
	protected void init() {
		findViews();
		radioGroup.setOnCheckedChangeListener(this);
	}

	@Override
	protected void onResume() {
		check(fangkuaiview);
		super.onResume();
	}

	private View fangkuaiview;


	public  void check(View fangkuaiview) {
		this.fangkuaiview = fangkuaiview;
		if (fangkuaiview != null) {
			tv_1_title = (TextView) fangkuaiview.findViewById(R.id.tv_1_title);
			tv_2_title = (TextView) fangkuaiview.findViewById(R.id.tv_2_title);
			tv_3_title = (TextView) fangkuaiview.findViewById(R.id.tv_3_title);
			tv_4_title = (TextView) fangkuaiview.findViewById(R.id.tv_4_title);
			tv_1 = (TextView) fangkuaiview.findViewById(R.id.tv_1);
			tv_2 = (TextView) fangkuaiview.findViewById(R.id.tv_2);
			tv_3 = (TextView) fangkuaiview.findViewById(R.id.tv_3);
			tv_4 = (TextView) fangkuaiview.findViewById(R.id.tv_4);
			tv_4_content = (TextView) fangkuaiview.findViewById(R.id.tv_4_content);
		}else{
			tv_1_title = (TextView) findViewById(R.id.tv_1_title);
			tv_2_title = (TextView) findViewById(R.id.tv_2_title);
			tv_3_title = (TextView) findViewById(R.id.tv_3_title);
			tv_4_title = (TextView) findViewById(R.id.tv_4_title);
			tv_1 = (TextView) findViewById(R.id.tv_1);
			tv_2 = (TextView) findViewById(R.id.tv_2);
			tv_3 = (TextView) findViewById(R.id.tv_3);
			tv_4 = (TextView) findViewById(R.id.tv_4);
			tv_4_content = (TextView) findViewById(R.id.tv_4_content);
		}
		Hehuoren hehuoren = HehuorenUtil.getHehuoren(context);
		if (this.getClass().equals(Act_Shouru_List.class)) {
			rb_shouye.setChecked(true);
			if (tv_1_title != null) {
				tv_1_title.setText("今日佣金");
				tv_1.setText("￥" + hehuoren.today_commission);
				tv_2_title.setText("本月佣金");
				tv_2.setText("￥" + hehuoren.week_commission);
				tv_3_title.setText("冻结金额");
				tv_3.setText("￥" + hehuoren.freezing_amount);
				tv_4_title.setText("账户金额");
				tv_4.setText("￥" + hehuoren.account_balance);
				tv_4_content.setOnClickListener(listener);
			}

		} else if (this.getClass().equals(Act_DingdanList.class)) {
			rb_fenlei.setChecked(true);
			if (tv_1_title != null) {
				tv_1_title.setText("完成订单");
				tv_1.setText(hehuoren.complete_order + "单");
				tv_2_title.setText("取消订单");
				tv_2.setText(hehuoren.cancel_order + "单");
				tv_3_title.setText("退款退货");
				tv_3.setText(hehuoren.refund_order + "单");
				tv_4_title.setText("账户余额");
				tv_4.setText("￥" + hehuoren.account_balance);
				tv_4_content.setOnClickListener(listener);
			}
		} else if (this.getClass().equals(Act_Gonghuoshang_List.class)) {
			rb_jhc.setChecked(true);
		} else if (this.getClass().equals(Act_Huiyuan_List.class)) {
			rb_wode.setChecked(true);
		} else if (this.getClass().equals(Act_Tixian.class)) {
			rb_shouye.setChecked(false);
			rb_fenlei.setChecked(false);
			rb_jhc.setChecked(false);
			rb_wode.setChecked(false);
			if (tv_1_title != null) {
				tv_1_title.setText("提现次数");
				tv_1.setText(hehuoren.number + "次");
				tv_2_title.setText("已提现金额");
				tv_2.setText("￥" + hehuoren.complete_amount);
				tv_3_title.setText("审核金额");
				tv_3.setText("￥" + hehuoren.fail_amount);
				tv_4_title.setText("账户余额");
				tv_4.setText("￥" + hehuoren.account_balance);
				tv_4_content.setVisibility(View.GONE);
			}
		} else if (this.getClass().equals(Act_Tixian_Record.class)) {
			rb_shouye.setChecked(false);
			rb_fenlei.setChecked(false);
			rb_jhc.setChecked(false);
			rb_wode.setChecked(false);
			if (tv_1_title != null) {
				tv_1_title.setText("提现次数");
				tv_1.setText(hehuoren.number + "次");
				tv_2_title.setText("已提现金额");
				tv_2.setText("￥" + hehuoren.complete_amount);
				tv_3_title.setText("审核金额");
				tv_3.setText("￥" + hehuoren.fail_amount);
				tv_4_title.setText("账户余额");
				tv_4.setText("￥" + hehuoren.account_balance);
				tv_4_content.setOnClickListener(listener);
			}
		} else

		{
			rb_shouye.setChecked(false);
			rb_fenlei.setChecked(false);
			rb_jhc.setChecked(false);
			rb_wode.setChecked(false);
		}
	}

	/**
	 * 提现的点击时间
	 */
	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = new Intent();
			intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			intent.setClass(context, Act_Tixian.class);
			startActivity(intent);
		}
	};

	private void findViews() {
		radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
		rb_shouye = (RadioButton) findViewById(R.id.rb_shouye);
		rb_fenlei = (RadioButton) findViewById(R.id.rb_fenlei);
		rb_jhc = (RadioButton) findViewById(R.id.rb_jhc);
		rb_wode = (RadioButton) findViewById(R.id.rb_wode);
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		Intent intent = new Intent();
		intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
		switch (checkedId) {
		case R.id.rb_shouye:
			intent.setClass(context, Act_Shouru_List.class);
			break;
		case R.id.rb_fenlei:
			intent.setClass(context, Act_DingdanList.class);
			break;
		case R.id.rb_jhc:
			intent.setClass(context, Act_Gonghuoshang_List.class);
			break;
		case R.id.rb_wode:
			intent.setClass(context, Act_Huiyuan_List.class);
			break;
		}
		startActivity(intent);
	}

}
